package com.upsuns.server;

import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.AlreadyBoundException;
import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;

import com.upsuns.service.FileService;
import com.upsuns.service.FileServiceImp;

/**
 *@Description:<p>RMI服务端，负责注册远程对象，文件数据源就在服务端上</p>
 *@author 王旭
 *@time 2016年3月14日 下午10:06:14
 */
public class Server {
	
	private FileService fileService;
	
	public Server(String path) throws IOException {
		this.fileService = new FileServiceImp(path);
	}

	public void doServer() throws RemoteException, MalformedURLException, AlreadyBoundException {
		//远程对象注册表实例
		LocateRegistry.createRegistry(8888);
		//把远程对象注册到RMI注册服务器上
		Naming.bind("rmi://localhost:8888/file", fileService);
		System.out.println("文件正在传输...");
		System.out.println(this.fileService.isFinished());
		while(true){}
	}
}
